#ifndef __GSINGAL_H__
#define __GSINGAL_H__

class  CXUIBasicConnection0
{
public:
	virtual ~CXUIBasicConnection0(){}
	virtual void exec() = 0;
};


template<class TargetType>
class CGConnection : public CXUIBasicConnection0
{
private:
	TargetType* m_pObject_;
	TargetType& (TargetType::* memberFunction_)();
	void (TargetType::* voidMemberFunction_)();
public:
	/*!
	\brief
	Constructor for a Connection0.
	*/
	CGConnection()
	{
		this->m_pObject_ = 0;
		memberFunction_ = 0;
		voidMemberFunction_ = 0;
	}

	CGConnection(TargetType* pAnObject, void (TargetType::*aMemberFunction)())
	{
		this->m_pObject_ = pAnObject;
		memberFunction_ = 0;
		voidMemberFunction_ = aMemberFunction;
	}

	CGConnection(TargetType* pAnObject, TargetType& (TargetType::*aMemberFunction)())
	{
		this->m_pObject_ = pAnObject;
		memberFunction_ = aMemberFunction;
	}


	virtual void exec()
	{
		if(memberFunction_ != 0)
			(this->m_pObject_->*memberFunction_)();
		else
			(this->m_pObject_->*voidMemberFunction_)();
	}

};

class  CGSignal
{
public:
	CXUIBasicConnection0 *m_pConnection;
public:
	/*!
	\brief
	Constructor for a Signal0.
	*/
	CGSignal() 
	{
		m_pConnection = NULL;
	}


	CGSignal(const CGSignal& s){}

	template<class TargetType>
	void connect(TargetType* pSlotHolder, void (TargetType::*aMemberFunction)())
	{
		CGConnection<TargetType>* conn =
			new CGConnection<TargetType>(pSlotHolder, aMemberFunction);
		m_pConnection = conn;
	}

	template<class TargetType>
	void connect(TargetType* pSlotHolder, TargetType& (TargetType::*aMemberFunction)())
	{
		CGConnection<TargetType>* conn =
			new CGConnection<TargetType>(pSlotHolder, aMemberFunction);
		m_pConnection = conn;

	}

	void exec()
	{
		if ( m_pConnection )
			m_pConnection->exec();
	}
	void operator()()
	{
		if ( m_pConnection )
			m_pConnection->exec();
	}


};

#endif //__GSINGAL_H__
